package com.tg.app.helper;

import androidx.annotation.NonNull;

import com.tange.core.backend.service.http.ClientObserver;
import com.tg.data.http.entity.DeviceServiceStatusBean;
import com.tg.network.socket.http.TGHttp;

import java.util.HashMap;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class ServiceInfoHelper {
    public static void getServiceInfo(String uuid, @NonNull final ServiceInfoListener<HashMap<String, DeviceServiceStatusBean>> listener){
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("uuid", uuid);
        TGHttp.getInstance().getDeviceService(hashMap)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ClientObserver<HashMap<String, DeviceServiceStatusBean>>() {
                    @Override
                    protected void onSuccess(final HashMap<String, DeviceServiceStatusBean> resp) {
                        listener.onSuccess(resp);
                    }

                    @Override
                    protected void onResponseError(int errorCode, String errorInfo) {
                        listener.onError(errorCode, errorInfo);

                    }

                    @Override
                    protected void onOtherError(String error) {
                        listener.onError(-99, error);
                    }
                });
    }

    public interface ServiceInfoListener<T> {
        void onSuccess(T content);
        void onError(int errorCode, String errorInfo);
    }
}
